{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.2 概率论"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "加法率：\n",
    "\n",
    "$$\n",
    "P(X) = \\sum_Y P(X,Y)\n",
    "$$\n",
    "\n",
    "乘法率：\n",
    "\n",
    "$$\n",
    "P(X,Y)=P(Y|X)P(X)=P(Y,X)=P(X|Y)P(Y)\n",
    "$$\n",
    "\n",
    "由乘法率可得 `Bayes` 公式：\n",
    "\n",
    "$$\n",
    "P(Y|X)=\\frac{P(X|Y)P(Y)}{P(X)}\n",
    "$$\n",
    "\n",
    "再由加法率和乘法率，`Bayes` 公式的分母可以写成：\n",
    "\n",
    "$$\n",
    "P(X) = \\sum_Y P(X,Y) = \\sum_Y P(X|Y)P(Y)\n",
    "$$\n",
    "\n",
    "所以 `Bayes` 公式的分母可以看成是一个归一化项，使得条件概率 $P(Y|X)$ 对所有的 $Y$ 求和之后和为 `1`。\n",
    "\n",
    "如果\n",
    "$P(X,Y)=P(X)P(Y)\n",
    "$，那么 $X, Y$ 是独立的。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2.1 概率密度函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 概率密度函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于实值变量 $x$，概率密度函数（`probability density function`） $p(x)$ 定义为：当$\\delta x>0, \\delta x\\rightarrow 0$ 时，变量 $x$ 落在区间 $(x,x+\\delta x)$ 范围内的概率为 $p(x)\\delta x$。\n",
    "\n",
    "$x$ 落在任意区间 $(a,b)$ 的概率为：\n",
    "\n",
    "$$\n",
    "P(x\\in (a,b)) = \\int_{a}^b p(x) dx \n",
    "$$\n",
    "\n",
    "对于概率密度函数，它需要满足两个条件：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "p(x)&\\geq 0 \\\\\n",
    "\\int_{-\\infty}^\\infty p(x) dx&=1\n",
    "\\end{align}\n",
    "$$\n",
    "\n",
    "对于随机变量间这样的一个变换 $x=g(y)$，设 $x,y$ 的概率密度函数分别为 $p_x(x)$ 和 $p_y(y)$，那么 $x$ 落在 $(x, x+\\delta x)$ 可以对应于 $y$ 落在 $(y, y+\\delta y)$ 的情况，并有 $p_x(x)\\delta x\\simeq p_y(y)\\delta y$，从而：\n",
    "\n",
    "$$\n",
    "p_y(y)=p_x(x)\\left|\\frac{dy}{dx}\\right|=p_x(g(y))\\left|g'(y)\\right|\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 累积分布函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "累积分布函数（`cumulative distribution function`）定义为：\n",
    "\n",
    "$$\n",
    "P(z)=\\int_{-\\infty}^zp(x) dx\n",
    "$$\n",
    "\n",
    "满足：\n",
    "\n",
    "$$\n",
    "P'(x) = p(x)\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 联合概率密度分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于多个变量 $x_1, \\dots, x_D$（用 $\\mathbf x$ 表示），定义联合概率密度为 $p(\\mathbf x)=p(x_1,\\dots,x_D)$，满足当 $\\mathbf x$ 落在一个包含 $\\mathbf x$ 的足够小的空间体积 $\\delta \\mathbf x$ 中时，其概率为 $p(\\mathbf x)\\delta \\mathbf x$。\n",
    "\n",
    "它也需要满足：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "p(\\mathbf x)&\\geq 0 \\\\\n",
    "\\int p(\\mathbf x) dx&=1\n",
    "\\end{align}\n",
    "$$\n",
    "\n",
    "其中积分是对整个空间进行积分。\n",
    "\n",
    "对于概率密度函数，我们的加法法则乘法法则仍然适用：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "p(x) & = \\int p(x,y) dy \\\\\n",
    "p(x,y) & = p(y|x)p(x)\n",
    "\\end{align}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 概率质量函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于离散的 $x$ 我们有时候将概率密度函数叫做概率质量函数，因为它的质量相当于集中在了某个允许的 $x$ 上。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2.2 期望和方差"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 期望"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "函数 $f(x)$ 在概率密度函数 $p(x)$ 下的均值叫做 $f(x)$ 的期望（`expectation`）。\n",
    "\n",
    "离散分布下，定义为：\n",
    "\n",
    "$$\\mathbb E\\left[f\\right] = \\sum_x p(x) f(x)$$\n",
    "\n",
    "连续分布下，定义为：\n",
    "\n",
    "$$\n",
    "\\mathbb E\\left[f\\right] = \\int p(x) f(x) dx\n",
    "$$\n",
    "\n",
    "如果给定了 $N$ 个从 $p(x)$ 中随机抽样的点，那么期望可以近似为\n",
    "\n",
    "$$\n",
    "\\mathbb E\\left[f\\right] \\simeq \\frac 1 N \\sum_{n=1}^N f(x_n)\n",
    "$$\n",
    "\n",
    "当 $N\\rightarrow \\infty$ 是，等式成立。\n",
    "\n",
    "多元函数可以对其中的一个参数求期望，例如 $\\mathbb E_x\\left[f(x,y)\\right]$ 是函数 $f(x,y)$ 在概率密度 $f(x)$ 上的期望，注意，它是一个关于 $y$ 的函数。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 条件期望 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们可以考虑一个函数 $f(x)$ 在条件分布 $p(x|y)$ 下的条件期望（`conditional expectation`），当 $x$ 是离散变量，定义为：\n",
    "\n",
    "$$\n",
    "\\mathbb E_x[f|y]= \\sum_x p(x|y) f(x)\n",
    "$$\n",
    "\n",
    "当 $x$ 是连续变量时，定义为\n",
    "\n",
    "$$\n",
    "\\mathbb E_x[f|y]= \\int p(x|y) f(x) dx\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 方差"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$f(x)$ 的方差（`variance`）定义为：\n",
    "\n",
    "$$\n",
    "\\operatorname{var}[f] = \\mathbb E\\left[(f(x) - \\mathbb E[f(x)])^2\\right]\n",
    "$$\n",
    "\n",
    "它表示 $f(x)$ 偏离其均值 $\\mathbb E[f(x)]$ 的程度。\n",
    "\n",
    "对平方进行展开之后，方差可以写成：\n",
    "\n",
    "$$\n",
    "\\operatorname{var}[f] = \\mathbb E[f(x)^2] - \\mathbb E[f(x)]^2\n",
    "$$\n",
    "\n",
    "特别地，我们考虑 $x$ 本身的方差：\n",
    "\n",
    "$$\n",
    "\\operatorname{var}[x] = \\mathbb E[x^2] - \\mathbb E[x]^2\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 协方差"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于两个随机变量 $x, y$，其协方差（`covariance`）定义为：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "\\operatorname{cov}[x,y] \n",
    "& = \\mathbb E_{x,y} \\left[(x-\\mathbb E[x])(y-\\mathbb E[y])\\right] \\\\\n",
    "& = \\mathbb E_{x,y} [xy] - \\mathbb E[x]\\mathbb E[y] \n",
    "\\end{align}\n",
    "$$\n",
    "\n",
    "当变量 $x,y$ 独立时，协方差为 $0$。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 协方差矩阵"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于两个随机向量 $\\mathbf{x, y}$，其协方差为一个矩阵：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "\\operatorname{cov}[\\mathbf{x, y}] \n",
    "& = \\mathbb E_{\\mathbf{x, y}} \\left[(\\mathbf x-\\mathbb E[\\mathbf x])(\\mathbf y^\\top-\\mathbb E[\\mathbf y^\\top])\\right] \\\\\n",
    "& = \\mathbb E_{\\mathbf{x, y}} [\\mathbf{xy^\\top}] - \\mathbb E[\\mathbf x]\\mathbb E[\\mathbf y^\\top] \n",
    "\\end{align}\n",
    "$$\n",
    "\n",
    "如果只是考虑随机向量 $\\mathbf x$ 自身分量之间的协方差，那么我们有 $\\operatorname{cov}[\\mathbf x] \\equiv \\operatorname{cov}[\\mathbf{x, x}]$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2.3 Bayes 概率"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "假设我们有一组模型的参数 $\\mathbf w$，并且做出假定：这组参数服从一定的先验概率分布 $p(\\mathbf w)$。\n",
    "\n",
    "$\\mathcal D = \\{t_1, \\dots, t_n\\}$ 是我们观测到的一组数据，这组数据在参数 $\\mathbf w$ 下的条件概率分布为 $p(\\mathcal D|\\mathbf w)$。\n",
    "\n",
    "`Bayes` 公式告诉我们：\n",
    "\n",
    "$$\n",
    "p(\\mathbf w|\\mathcal D)=\\frac{p(\\mathcal D|\\mathbf w)p(\\mathbf w)}{p(\\mathcal D)}\n",
    "$$\n",
    "\n",
    "这给了我们一种衡量在观测到数据 $\\mathcal D$ 的情况下，参数 $\\mathbf w$ 的不确定性的方法。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 似然函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$p(\\mathcal D|\\mathbf w)$ 可以看成是给定观测数据 $\\mathcal D$ 的情况下关于参数向量 $\\mathbf w$ 的一个函数，通常叫做似然函数（`likelihood function`）。\n",
    "\n",
    "似然函数反映了在给定一组参数 $\\mathbf w$ 的情况下，生成这组观测数据的一种可能性。注意它并不是一个关于 $w$ 的概率分布。\n",
    "\n",
    "给定似然函数的定义，我们可以将上面的 Bayes 公式表示为：\n",
    "\n",
    "$$\n",
    "\\text{posterior} \\propto \\text{likelihood} \\times \\text{prior} \n",
    "$$\n",
    "\n",
    "这三个量都是 $\\mathbf w$ 的函数。\n",
    "\n",
    "对于分母，在给定观测数据 $\\mathcal D$ 的情况下是一个归一化常数，可以写成：\n",
    "\n",
    "$$\n",
    "p(\\mathcal D)=\\int p(\\mathcal D|\\mathbf w)p(\\mathbf w)d\\mathbf w\n",
    "$$\n",
    "\n",
    "在 Bayes 学派和频率学派的眼中，似然函数 $p(\\mathcal D|\\mathbf w)$ 都扮演了一个重要角色。但二者对于似然函数的使用方式是截然不同的。\n",
    "\n",
    "在频率学派眼中，$\\mathbf w$ 被看成是一个固定的参数，其值由某些估计量来决定，误差的计算要考虑数据 $\\mathcal D$ 的分布；在 Bayes 学派眼中，数据集 $\\mathcal D$ 是唯一的，参数 $\\mathbf w$的不确定性只来自于 $\\mathbf w$ 的一个概率分布。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 频率估计量：最大似然估计"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一个最常用的频率估计量就是最大似然（`maximum likelihood`）估计：\n",
    "\n",
    "$$\n",
    "\\mathbf w_{ML} = \\operatorname{argmax}_{\\mathbf w} p(\\mathcal D|\\mathbf w)\n",
    "$$\n",
    "\n",
    "这相当于选择使得观测数据 $\\mathcal D$ 出现的概率最大化的 $\\mathbf w$。\n",
    "\n",
    "在机器学习的文献中，似然函数的负对数通常被叫做一个损失函数（`error function`），因为负对数函数是单调递减的函数，因此最大似然就相当于最小化损失函数。\n",
    "\n",
    "一种衡量频率估计量误差大小的方法是 `bootstrap`：假设我们有 $N$ 个数据 $\\mathbf X=\\{\\mathbf x_1,\\dots,\\mathbf x_N\\}$，我们从这写数据中有放回的抽样 $N$ 个数据得到一组新的数据 $\\mathbf X_{\\text B}$。\n",
    "重复进行 $L$ 次这样的操作，得到 $L$ 组这样的抽样数据，然后可以通过这 $L$ 组抽样数据的统计结果估计最大似然估计的误差。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Bayes 估计"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Bayes` 估计的一个重要观点是先验知识的引入，根据后验概率来决定参数 $\\mathbf w$。\n",
    "\n",
    "考虑抛硬币的情况，假设我们抛三次，每次都得到正面，那么最大似然估计会得到这枚硬币会 `100%` 得到正面的结论，而 `Bayes` 估计不会得到这么极端的结论。\n",
    "\n",
    "两者并没有什么好坏之分，只不过是看问题的角度不同。`Bayes` 估计如果选定的先验不好，也可能得到很差的结果。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2.4 高斯分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "高斯分布（`Gaussian distribution`），又叫正态分布（`normal distribution`）。\n",
    "\n",
    "对于实值变量 $x$，高斯分布定义为：\n",
    "\n",
    "$$\n",
    "\\mathcal{N}\\left(x\\left|~\\mu,\\sigma^2\\right.\\right) = \\frac{1}{(2\\pi\\sigma^2)^{1/2}} \\exp\\left\\{-\\frac{1}{2\\sigma^2}(x-\\mu)^2\\right\\}\n",
    "$$\n",
    "\n",
    "参数为均值 $\\mu$ 和方差 $\\sigma^2$。方差的平方根 $\\sigma$ 叫做标准差，方差的倒数 $\\beta = \\frac{1}{\\sigma^2}$ 叫做精度。\n",
    "\n",
    "其图像如下所示："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAEDCAYAAAA7jc+ZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xm8zmX+x/HXhRqkKNKuXRSJVEiStEwzJbRLmqKFVstI\nZVCJSkxoOlFNSY0a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bG1F60km4SZP2GvQFUlpwXvXpY8GubpAi\nku0OPnjHAnd3W7fC0qUW+jVq7PUt0jPozzkndAUiIukvf3444QT72Ie03LoJXYOISCbKmD16ERFJ\nLPW6ERGJOAW9iEjEKehFRCJOQS8iEnEKehGRiFPQi4hEnIJeJA+cc1Odcxfu9M/HO+e+dc6l56VD\nkZ0o6EWYSigPAAABGElEQVT2wzl3GlAJWLDTy1cCG7z3W8JUJZJ3CnqR/asOzPfe/7DTaxcB4wPV\nI3JAFPQi+1cdGLfbazWAjwLUInLAFPQi+1ednULdOXc8cCJa0UuGUNCL7INzrgRQGpi108s1ge+9\n94udc62DFCZyABT0Ivt2EeCB/ADOuaLAfcBs55wjXVt9i+xE3StF9sE51wWoBSwEPge2Am8DrwBf\nADne+/nhKhTZPwW9yD445yYDr3nve4WuRSRW2roR2QvnXCGgIjApdC0i8VDQi+xdFWCj935m6EJE\n4qGgF9m7UsDg0EWIxEt79CIiEacVvYhIxCnoRUQiTkEvIhJxCnoRkYhT0IuIRJyCXkQk4hT0IiIR\np6AXEYm4/wcSdOSRJGqxUQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f3b9bdf5f10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import scipy as sp\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "from scipy.stats import norm\n",
    "\n",
    "xx = np.linspace(-3, 3, 200)\n",
    "\n",
    "norm_xx = norm.pdf(xx)\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "\n",
    "ax.plot(xx, norm_xx, \"r\")\n",
    "ax.set_ylim(0, 0.5)\n",
    "ax.set_ylabel(r\"$\\mathcal{N}\\left(x|\\mu,\\sigma^2\\right)$\", fontsize=\"xx-large\")\n",
    "ax.set_yticks([])\n",
    "ax.set_yticklabels([])\n",
    "\n",
    "ax.set_xticks([0])\n",
    "ax.set_xticklabels([r\"$\\mu$\"], fontsize=\"xx-large\")\n",
    "\n",
    "ax.text(-.1, 0.25, \"$2\\sigma$\", fontsize=\"xx-large\")\n",
    "\n",
    "ax.annotate(\"\",\n",
    "            xy=(-1, 0.24), xycoords='data',\n",
    "            xytext=(1, 0.24), textcoords='data',\n",
    "            arrowprops=dict(arrowstyle=\"<->\",\n",
    "                            connectionstyle=\"arc3\"), \n",
    "            )\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下面证明这是一个概率分布，首先，从定义中可以看出：\n",
    "\n",
    "$$\\mathcal{N}\\left(x\\left|~\\mu,\\sigma^2\\right.\\right) > 0$$\n",
    "\n",
    "然后是积分：\n",
    "\n",
    "$$\\int_{-\\infty}^{\\infty} \\mathcal{N}\\left(x\\left|~\\mu,\\sigma^2\\right.\\right) dx = 1$$\n",
    "\n",
    "这个结果可以通过计算 $I = \\int_{\\infty}^{\\infty} \\exp (x^2)dx$ 得到（计算 $I^2$，并换成极坐标计算）。\n",
    "\n",
    "$x$ 的期望为（令 $y = x + \\mu$，对 $y$ 的积分变成一个奇函数的积分加上 $\\mu$ 乘以一个高斯分布的积分）：\n",
    "\n",
    "$$\n",
    "\\mathbb E[x] = \\int_{-\\infty}^{\\infty} \\mathcal{N}\\left(x\\left|~\\mu,\\sigma^2\\right.\\right)x~dx = \\mu\n",
    "$$\n",
    "\n",
    "其方差为（等式 $\\int_{-\\infty}^{\\infty} \\exp\\left\\{ -\\frac{1}{2\\sigma^2}(x-\\mu)^2 \\right\\} dx = (2\\pi \\sigma^2)^{1/2}$ 两边对 $\\sigma^2$ 求导）：\n",
    "\n",
    "$$\n",
    "\\text var[x] = \\int_{-\\infty}^{\\infty} \\mathcal{N}\\left(x\\left|~\\mu,\\sigma^2\\right.\\right)(x-\\mu)^2dx =\\sigma^2\n",
    "$$\n",
    "\n",
    "因此：\n",
    "\n",
    "$$\n",
    "\\mathbb E[x^2] = \\mathbb E[x]^2 + \\text{var}[x] = \\mu^2 + \\sigma^2\n",
    "$$\n",
    "\n",
    "概率分布的最大值叫做众数（`mode`），高斯分布的众数就是均值 $\\mu$。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 多维高斯分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于 $D$ 维的向量 $\\mathbf x$，高斯分布定义为：\n",
    "\n",
    "$$\n",
    "\\mathcal{N}\\left(\\mathbf x\\left|~\\mathbf{\\mu, \\Sigma}\\right.\\right) = \\frac{1}{(2\\pi)^{D/2}} \\frac{1}{|\\mathbf\\Sigma|^{1/2}} \\exp \\left\\{-\\frac{1}{2}(\\mathbf x - \\mathbf \\mu)^\\top\\mathbf\\Sigma^{-1}(\\mathbf x - \\mathbf \\mu)\\right\\}\n",
    "$$\n",
    "\n",
    "其中，$D$ 维向量 $\\mathbf \\mu$ 是均值，$D\\times D$ 矩阵 $\\mathbf\\Sigma$ 是方差，$|\\mathbf\\Sigma|$ 是其行列式。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 最大似然估计"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "假设我们现在有 $N$ 组对 $x$ 的观测数据 $\\mathsf x = (x_1,\\dots,x_N)^{\\text T}$，这些数据是独立同分布（`independent and identically distributed, i.i.d.`）的，都服从一个均值 $\\mu$，方差 $\\sigma^2$ 的高斯分布。那么在给定这些参数的情况下，出现这些观测数据的概率，或者从参数的角度来说，似然函数为：\n",
    "\n",
    "$$\n",
    "p(\\mathsf x~|~\\mu, \\sigma^2)=\\prod_{n=1}^N \\mathcal N\\left(x_n \\left|~\\mu, \\sigma^2\\right.\\right)\n",
    "$$\n",
    "\n",
    "通常最大似然的问题经常转化为求最大对数似然的问题：\n",
    "\n",
    "$$\n",
    "\\ln p(\\mathsf x~|~\\mu, \\sigma^2) = -\\frac{1}{2\\sigma^2} \\sum_{n=1}^N(x_n - \\mu)^2 - \\frac N 2 \\ln \\sigma^2 - \\frac N 2 \\ln(2\\pi) \n",
    "$$\n",
    "\n",
    "对 $\\mu$ 最大化，我们得到最大似然解：\n",
    "\n",
    "$$\n",
    "\\mu_{ML} = \\frac 1 N \\sum_{n=1}^N x_n\n",
    "$$\n",
    "\n",
    "即样本均值。\n",
    "\n",
    "对 $\\sigma^2$ 最大化，我们得到：\n",
    "\n",
    "$$\n",
    "\\sigma^2_{ML} = \\frac 1 N \\sum_{n=1}^N (x_n-\\mu_{ML})^2\n",
    "$$\n",
    "\n",
    "即样本方差。\n",
    "\n",
    "但是这个解不是无偏的，我们可以计算它们的期望：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "\\mathbb E[\\mu_{ML}] & = \\frac 1 N \\sum_{n=1}^N \\mathbb E[x_n] = \\mu \\\\\n",
    "\\mathbb E[\\sigma^2_{ML}] & = \\mathbb E \\left[\\frac{1}{N} \\sum_{n=1}^N(x_n-\\frac 1 N \\sum_{m=1}^N x_m)\\right] \\\\\n",
    "& = \\frac 1 N \\sum_{i=1}^N \\mathbb E \\left[x_n^2-\\frac 2 N x_n\\sum_{m=1} x_m + \\frac{1}{N^2} \\sum_{m=1}^N\\sum_{l=1}^N x_mx_l\\right] \\\\\n",
    "& = (\\mu^2 + \\sigma^2) - 2 (\\mu^2+ \\frac 1 N \\sigma^2) + \\mu^2+ \\frac 1 N \\sigma^2 \\\\\n",
    "& = \\left(\\frac{N-1}{N}\\right)\\sigma^2\n",
    "\\end{align}\n",
    "$$\n",
    "\n",
    "用到了：\n",
    "- 当 $m=n$ 时，$\\mathbb E[x_mx_n]=\\mathbb E[x_n^2] = \\mu^2 + \\sigma^2$\n",
    "- 当 $m\\neq n$ 时，$\\mathbb E[x_mx_n]=\\mathbb E[x_n]\\mathbb E[x_m] = \\mu^2$\n",
    "\n",
    "因此，方差的一个无偏估计为：\n",
    "\n",
    "$$\n",
    "\\tilde \\sigma^2 = \\frac{N}{N-1}\\sigma^2_{ML}=\\frac{1}{N-1}\\sum_{n=1}^N(x_n-\\mu_{ML})^2\n",
    "$$\n",
    "\n",
    "随着 $N$ 的增大，方差估计的误差也随之增大。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2.5 重新理解曲线拟合"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于曲线拟合的问题，设训练集输入为 $\\mathsf x=(x_1, \\dots, x_N)^\\top$，对应的目标值为 $\\mathsf t=(t_1, \\dots, t_N)^\\top$。\n",
    "\n",
    "我们将我们的不确定性用高斯分布来表示，假设给定 $x$，对应的目标值 $t$ 服从一个均值为 $y(x,\\mathbf w)$ 的高斯分布：\n",
    "\n",
    "$$\n",
    "p(t\\left|~x,\\mathbf w,\\beta\\right.)=\\mathcal N\\left(t\\left|~y(x,\\mathbf w), \\beta^{-1}\\right.\\right)\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZwAAAEDCAYAAAABcbKvAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmczuX+x/HXd4aRsRxZxillSVIpEsoWKlSWigynplNO\npUWn7XCKKJE5qBAtZKLCVIxjySEtMhnLlF/Z6hghS1FZZqwzZr1+f1xjjmG2e8x9f+975v18POYx\nM/d8l89I99t1fa/FMcYgIiLibUFuFyAiImWDAkdERHxCgSMiIj6hwBEREZ9Q4IiIiE8ocERExCfK\nuV2AP3McR2PGRUSKwRjjnPmaAqcQmqck/mbePAgP74sxc90uRSRPjnNW1gDqUhMRER9R4IiIiE8o\ncEQCUhO3CxDxmAJHJCApcCTwKHBERMQnFDgiIuITChwREfEJBY6IiPiEAkdERHxCgSMiIj6hwBER\nEZ9Q4IiIiE8ocEREimHXrl3MnDnT7TKIjIwkLS3N7TKKRIEjIuKhxMREhg8fTkREhNul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GKXC8JTMT7rkHrrkGnn/e7WpERFynwPGWjAxo3RqmTtVcGxERNGjA\neypUUMtGROQ0auGIiIhPKHBERMQnFDgiIuITChwREfEJBY6IiPiEAkdERHxCgSMiIj6hwBEREZ9Q\n4IiIiE8ocERExCcUOCIi4hMKHBER8QkFjoiI+IQCR0REfEKBIxKQfnS7ABGPKXBEApICRwKPAkdE\nRHxCgSMiIj6hLaYL4TiO2yWI5El/NyXQOMYYt2sQEZEyQF1qIiLiEwocERHxCQWOiIj4hAJHRER8\nQoEjIiI+ocARERGfUOCIiIhPaOKniB9zHOcpIBRoDowAegMOcL4xZpCbtYl4ShM/RfyU4zhPAp8Z\nY7Y6jvMQEIkNnseAh40xtR3H6QE0BVKAZGPMO+5VLFIwtXBE/FewMWZr9tcXAeuNMfscx5kKzHIc\npwowyhhzLYDjOJ87jvOpMWaPWwWLFETPcET8lDFm4mnfdgBis1/fa4z5CegEJJx2zHfALb6qT8RT\nChwRP+c4TgjQGvj6jB/VAQ6f9v0R4DJf1SXiKQWOiB9yHKec4zg3Zn/bJvvzuuyf1XQc517gfODk\naaelAVV8V6WIZxQ4Iv7pYWCp4zgVgZ7AIWNMRvbP/g78BziGHbF2SkUg0adVinhAgwZE/NNKYD4w\nNPvzCcdxxgPJQIwx5rDjODuwXW2n1AC2+7xSkSLSsGiRAOU4TiiwzhjTJPv7tUCEMeZndysTyZsC\nRySAOY4TAVwCpAJHNA9H/JkCR0REfEKDBkRExCcUOCIi4hMKHBER8QkFjoiI+IQCR0REfEKBIyIi\nPqHAERERn1DgiIiITyhwRETEJ/4fzxDyYrBoeKUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f3bbc15e610>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "xx = np.linspace(-0.9, 0.9, 100)\n",
    "yy = 4 * xx - np.sin(xx * np.pi)\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "ax.plot(xx, yy, color=\"red\")\n",
    "\n",
    "ax.set_xlim(-1, 1)\n",
    "ax.set_ylim(-4, 4)\n",
    "\n",
    "ax.set_xticks([0])\n",
    "ax.set_xticklabels([r'$x_0$'], fontsize=\"xx-large\")\n",
    "ax.set_yticks([0])\n",
    "ax.set_yticklabels([r'$y(x_0, \\mathbf{w})$'], fontsize=\"xx-large\")\n",
    "\n",
    "xx = np.linspace(-4, 4, 100)\n",
    "yy = norm.pdf(xx, scale=0.5) / 5\n",
    "\n",
    "ax.plot([-1, 0], [0, 0], \"g--\")\n",
    "ax.plot([0, 0], [-4, 4], \"k\")\n",
    "ax.plot(yy, xx)\n",
    "\n",
    "ax.annotate(\"\",\n",
    "            xy=(0.75, -0.5), xycoords='data',\n",
    "            xytext=(0.75, 0.5), textcoords='data',\n",
    "            arrowprops=dict(arrowstyle=\"<->\",\n",
    "                            connectionstyle=\"arc3\"), \n",
    "            )\n",
    "\n",
    "ax.text(0.77, -0.2, r'$2\\sigma$', fontsize=\"xx-large\")\n",
    "ax.text(0.15, -1, r'$p(t|x_0,\\mathbf{w}, \\beta)$', fontsize=\"xx-large\")\n",
    "ax.text(0.5, 3, r'$y(x, \\mathbf{w})$', fontsize=\"xx-large\")\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 最大似然"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "设训练集数据是独立同分布的，那么似然函数为：\n",
    "\n",
    "$$\n",
    "p(\\mathsf t \\left|\\mathsf x, \\mathbf w, \\beta\\right.)\n",
    "= \\sum_{i=1}^N \\mathcal{N}\\left(t_n\\left|~y(x,\\mathbf w), \\beta^{-1}\\right.\\right)\n",
    "$$\n",
    "\n",
    "对数似然为：\n",
    "\n",
    "$$\n",
    "\\ln p(\\mathsf t \\left|\\mathsf x, \\mathbf w, \\beta\\right.) = -\\frac{\\beta}{2} \\sum_{n=1}^N \\{y(x,\\mathbf w) - t_n\\}^2 + \\frac N 2 \\ln \\beta - \\frac N 2 \\ln(2\\pi) \n",
    "$$\n",
    "\n",
    "设系数的最大似然解为 $\\mathbf w_{ML}$，从最大化对数似然的角度来看，求它的问题相当于最小化：\n",
    "\n",
    "$$\n",
    "\\frac{1}{2} \\sum_{n=1}^N \\{y(x,\\mathbf w) - t_n\\}^2\n",
    "$$\n",
    "\n",
    "这就是之前最小化平方误差和的结果。\n",
    "\n",
    "因此最小化平方误差和可以看成是高斯噪音假设下的最大似然的结果。\n",
    "\n",
    "再对精度 $\\beta$ 求最大似然，我们有（可以理解为照搬之前求 $\\sigma^2$ 的结果）：\n",
    "\n",
    "$$\n",
    "\\frac{1}{\\beta_{ML}} = \\frac{1}{N}\\sum_{i=1}^N \\{y(x,\\mathbf w) - t_n\\}^2\n",
    "$$\n",
    "\n",
    "我们有了最大似然的结果之后，对于一个新的输入 $x$，其输出 $t$ 应当满足：\n",
    "\n",
    "$$\n",
    "p\\left(t\\left|~x,\\mathbf w_{ML}, \\beta_{ML}\\right.\\right) = \\mathcal N\\left(t\\left|~y(x,\\mathbf w_{ML}), \\beta_{ML}^{-1}\\right.\\right)\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 最大化后验分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "假设我们对系数 $\\mathbf w$ 有一个先验的知识（$M$ 是多项式阶数，加上常数项一共 $M+1$ 维）：\n",
    "\n",
    "$$\n",
    "p(\\mathbf w~|~\\alpha) = \\mathcal{N}(\\mathbf w~|~\\mathbf 0, \\alpha^{-1} I)\n",
    "= \\left(\\frac{\\alpha}{2\\pi}\\right)^{(M+1)/2} \\exp\\left\\{-\\frac{\\alpha}{2}\\mathbf{w}^\\top\\mathbf{w}\\right\\}\n",
    "$$\n",
    "\n",
    "$\\alpha$ 控制这个模型的先验分布，这一类的参数通常被叫做超参（`hyperparameters`），Bayes 公式告诉我们，后验概率正比与先验概率和似然函数的乘积：\n",
    "\n",
    "$$\n",
    "p(\\mathbf w~|~\\mathsf{x, t}, \\alpha, \\beta) \\propto p(\\mathsf t~|~\\mathsf x, \\mathbf w, \\beta)~p(\\mathbf w~|~\\alpha) \n",
    "$$\n",
    "\n",
    "我们可以通过最大化后验概率（`maximum posterior, MAP`）来决定参数 $\\mathbf w$ 的值，对上式求对数，并去掉跟 $\\mathbf w$ 无关的项，我们相当于要最大化：\n",
    "\n",
    "$$\n",
    "-\\frac{\\beta}{2} \\sum_{n=1}^N \\{y(x,\\mathbf w) - t_n\\}^2 -\\frac{\\alpha}{2}\\mathbf{w}^\\top\\mathbf{w}\n",
    "$$\n",
    "\n",
    "即最小化\n",
    "\n",
    "$$\n",
    "\\frac{\\beta}{2} \\sum_{n=1}^N \\{y(x,\\mathbf w) - t_n\\}^2 +\\frac{\\alpha}{2}\\mathbf{w}^\\top\\mathbf{w}\n",
    "$$\n",
    "\n",
    "因此，`MAP` 的结果相当于给多项式拟合加二范数正则化的结果，其中正则参数 $\\lambda = \\alpha / \\beta$。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2.6 Bayes 曲线拟合"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "虽然在 `MAP` 中，我们引入了先验分布，但是本质上它还是一个点估计，本质上并不是一个完全的 `Bayes` 估计。\n",
    "\n",
    "一个完全的 `Bayes` 估计要求我们对 $\\mathbf w$ 的所有值进行积分。\n",
    "\n",
    "对于之前的曲线拟合问题，给定训练集 $\\mathsf x$ 和 $\\mathsf t$，对于一个新的测试样例 $x$，其目标值为 $t$，我们考虑预测的分布 $p(t~|~x,\\mathsf{x, t})$（这里我们假定 $\\beta, \\alpha$ 两个参数已经给定了）\n",
    "\n",
    "Bayes 公式给出：\n",
    "\n",
    "$$\n",
    "p(t~|~x,\\mathsf{x, t}) = \\int p(t~|~x,\\mathbf w) p(w~|~\\mathsf{x,t})d\\mathbf w\n",
    "$$\n",
    "\n",
    "其中 $p(t~|~x,\\mathbf w)$ 是之前给定的高斯分布，$p(w~|~\\mathsf{x,t})$ 是训练集上的后验概率（也是一个高斯分布）。\n",
    "\n",
    "由于高斯分布的性质，上面的式子本质上也是一个高斯分布，因此可以写成\n",
    "\n",
    "$$\n",
    "p(t~|~x,\\mathsf{x, t})=\\mathcal{N}\\left(t~|~m(x), s^2(x)\\right)\n",
    "$$\n",
    "\n",
    "其中均值和方差分别为\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "m(x) & = \\beta \\phi(x)^\\text{T} \\mathbf S \\sum_{n=1}^N \\phi(x_n) t_n \\\\\n",
    "s^2(x) & = \\beta^{-1} + \\phi(x)^\\top \\mathbf S \\phi(x) \n",
    "\\end{align}\n",
    "$$\n",
    "\n",
    "其中，$\\phi_i(x) = x^i, i = 0, \\dots, M$，矩阵 $\\mathbf S$：\n",
    "\n",
    "$$\n",
    "\\mathbf S^{-1}=\\alpha I +\\beta \\sum_{n=1}^N \\phi(x_n)^\\top\\phi(x_n) \n",
    "$$\n",
    "\n",
    "下图粉红色部分就是 Bayes 估计给出的结果，红色曲线是 `MAP` 给出的结果。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEOCAYAAACEiBAqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlcVPX+x/HXOeyLgoCKgIqC4q6V5a1+FdX1Wt1svXVb\n7Gpllpr7WrklprmklVu2uLSY2Z7d9sXq2s30trgrIOACLiiK7DBzfn98RUUZGJgzMMN8no+Hj4Rz\n5szXxPOe810+X80wDIQQQnguvb4bIIQQon5JEAghhIeTIBBCCA8nQSCEEB5OgkAIITycBIEQQng4\n7/puQG1omiZzXoUQohYMw9DO/55bBgFAXa5/mDZtGtOmTauz9xNCeIa6vrdo2gUZAEjXkBBCeDwJ\nAiGE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s5tB4vruw1CCOGOGsysISGEEOaRriEhhPBwEgRCCOHhJAiqoGnaDZqm7dI0bY+maRPq\nuz1CiIZB07TXNE07rGnalvpuC0gQ2KRpmg4sAvoAnYF7NU3rUL+tEkI0ECtQ9xaXIEFg22VAsmEY\nGYZhlAJrgFvruU1CiAbAMIz/ADn13Y5yEgS2RQP7z/n6wOnvCSFEgyJBIIQQHk6CwLaDQKtzvo45\n/T0hhGhQJAhs2wTEa5rWWtM0X+Ae4JN6bpMQouE4fwOHeiNBYINhGBbgceArYDuwxjCMnfXbKiFE\nQ6Bp2mrgZ6C9pmn7NE17sF7bIyUmhBDCs8kTgRBCeDgJAiGE8HASBEII4eEkCIQQwsNJEAghhIeT\nIBBCCA8nQSCEEB5OgkAIITycBIEQQng4CQIhhPBwEgRCCOHhvOu7AUI0BJqmtQOuBsKAMqAI6Ahs\nNAzjrfpsmxDVkSAQwkGapmnADYZhLNQ0rSmQBrQEBgHH67VxQthBqo8K4SBN03QgwDCMfE3TbgUe\nMW/5Qy0AAACiSURBVAzj5vpulxD2kicCIRxkGIYVyD/95Y3AlwCapvkAumEYxfXVNiHsIYPFQjhI\n07SemqbNP72TXV9g4+lD/ZEPW8INSNeQEA7SNO164CHgF+AU0BnYAewwDGNjVa8VwhVIEAghhIeT\nriEhhPBwEgRCCOHhJAiEEMLDSRAIIYSHkyAQQggPJ0EghBAeToJACCE8nASBEEJ4OAkCIYTwcP8P\nol2Ma66SdT8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f3bbc103150>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def phi(x, M):\n",
    "    return x[:,None] ** np.arange(M + 1)\n",
    "\n",
    "N = 10\n",
    "\n",
    "# 生成 0，1 之间等距的 N 个 数\n",
    "x_tr = np.linspace(0, 1, N)\n",
    "\n",
    "# 计算 t\n",
    "t_tr = np.sin(2 * np.pi * x_tr) + 0.25 * np.random.randn(N)\n",
    "\n",
    "# 加正则项的解\n",
    "M = 9\n",
    "alpha = 5e-3\n",
    "beta = 11.1\n",
    "lam = alpha / beta\n",
    "\n",
    "phi_x_tr = phi(x_tr, M)\n",
    "A_0 = phi_x_tr.T.dot(phi_x_tr) + lam * np.eye(M+1)\n",
    "y_0 = t_tr.dot(phi_x_tr)\n",
    "\n",
    "# 求解 Aw=y\n",
    "coeff = np.linalg.solve(A_0, y_0)[::-1]\n",
    "\n",
    "f = np.poly1d(coeff)\n",
    "\n",
    "# 绘图\n",
    "\n",
    "xx = np.linspace(0, 1, 500)\n",
    "\n",
    "# Bayes估计的均值和标准差\n",
    "S = np.linalg.inv(A_0 * beta)\n",
    "\n",
    "m_xx = beta * phi(xx, M).dot(S).dot(y_0)\n",
    "s_xx = np.sqrt(1 / beta + phi(xx, M).dot(S).dot(phi(xx, M).T).diagonal())\n",
    "\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "ax.plot(x_tr, t_tr, 'co')\n",
    "ax.plot(xx, np.sin(2 * np.pi * xx), 'g')\n",
    "ax.plot(xx, f(xx), 'r')\n",
    "ax.fill_between(xx, m_xx-s_xx, m_xx+s_xx, color=\"pink\")\n",
    "ax.set_xlim(-0.1, 1.1)\n",
    "ax.set_ylim(-1.5, 1.5)\n",
    "ax.set_xticks([0, 1])\n",
    "ax.set_yticks([-1, 0, 1])\n",
    "ax.set_xlabel(\"$x$\", fontsize=\"x-large\")\n",
    "ax.set_ylabel(\"$t$\", fontsize=\"x-large\")\n",
    "\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
